label: Stop using screen width/height
authorMatthias Clasen <mclasen@redhat.com>
Mon, 11 Apr 2016 03:43:34 +0000 (23:43 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 28 Apr 2016 03:18:16 +0000 (23:18 -0400)
Popups should always be placed relative to a monitor.

gtk/gtklabel.c

index 646415722999dcac21dcc107116d74b65fd36f85..6498a3bcbeac769b759df8362741b0b2ff41aeb1 100644 (file)
@@ -6560,31 +6560,35 @@ popup_position_func (GtkMenu   *menu,
   GtkWidget *widget;
   GtkAllocation allocation;
   GtkRequisition req;
-  GdkScreen *screen;
+  GdkDisplay *display;
+  GdkMonitor *monitor;
+  GdkRectangle workarea;
 
   label = GTK_LABEL (user_data);
   widget = GTK_WIDGET (label);
 
   g_return_if_fail (gtk_widget_get_realized (widget));
 
-  screen = gtk_widget_get_screen (widget);
-  gdk_window_get_origin (gtk_widget_get_window (widget), x, y);
+  display = gtk_widget_get_display (widget);
+  monitor = gdk_display_get_monitor_at_window (display,
+                                               gtk_widget_get_window (widget));
+  gdk_monitor_get_workarea (monitor, &workarea);
 
+  gdk_window_get_origin (gtk_widget_get_window (widget), x, y);
   gtk_widget_get_allocation (widget, &allocation);
 
   *x += allocation.x;
   *y += allocation.y;
 
-  gtk_widget_get_preferred_size (GTK_WIDGET (menu),
-                                 &req, NULL);
+  gtk_widget_get_preferred_size (GTK_WIDGET (menu), &req, NULL);
 
   gtk_widget_get_allocation (widget, &allocation);
 
   *x += allocation.width / 2;
   *y += allocation.height;
 
-  *x = CLAMP (*x, 0, MAX (0, gdk_screen_get_width (screen) - req.width));
-  *y = CLAMP (*y, 0, MAX (0, gdk_screen_get_height (screen) - req.height));
+  *x = CLAMP (*x, 0, MAX (0, workarea.width - req.width));
+  *y = CLAMP (*y, 0, MAX (0, workarea.height - req.height));
 }
 
 static void